Page({
  mixins: [require('../../mixin/common')],
  data: {
    inputShowed: false,
    inputVal: '',
    wordList:['nihao','湖南','夏天']
  },
  query(options){
    let that =this
    let key =this.options.currentTarget.dataset.key
    console.log(key);
    this.setData({inputVal:''})
    let db=wx.cloud.database()
    db.collection('top250')
    .get({
      success:(res)=>{
        that.setData({
          subjects:res.data[0].subjects
        })
        let tempArray =this.data.subjects.filter((value,index,array)=>{
          return value.title.indexOf(key)!=-1
        })
        console.log(tempArray);
        that.setData({
          subjects:tempArray
        })
        
      }
    })

  },
  showInput() {
    this.setData({
      inputShowed: true,
    });
  },
  hideInput(options) {
    console.log("options");
    this.query(options)
    
    this.setData({
      inputVal: '',
      inputShowed: false
    });
  },
  clearInput() {
    this.setData({
      inputVal: '',
    });
  },
  inputTyping(e) {
    this.setData({
      inputVal: e.detail.value,
    });
    let db =wx.cloud.database()
    let searchCollection = db.collection('search')
    searchCollection.get().then(res=>{
       console.log(res.data[0].subjects); 
       this.setData({
         wordList:res.data[0].subjects
       })
    })
  },
});
